/** \file srg_driver.c Contains the definition for functions and variables of the Shift Register Driver component.
*/
#include "srg_dirver.h"

/*********************/
/*	Local Dfinitions */
/*********************/
#define SRG_u8CLEAR_DATA_PORT       (u8)0x80

#define u8NUMBER_OF_COLOMNS			(u8)15 /*MAIN_nSCREEN*/

/*******************/
/*	Local Variables*/
/*******************/



/*********************************/
/*	Local Functions' Declaration */
/*********************************/




/***********************************/
/*	External Functions' Definition */
/***********************************/
void SRG_vidInit(void)
{

    u8 u8Iterator;

	SRG_u8CONTROL_PORT_DDR |= (1<<SRG_bSCK_DDR) | (1<<SRG_bRCK_DDR) | (1<<SRG_bSI_DDR);
	
	SRG_u8DATA_PORT_DDR |= ~(SRG_u8CLEAR_DATA_PORT);

    SRG_u8CONTROL_PORT |= (1<<SRG_bSI);

    for (u8Iterator = 0; u8Iterator < u8NUMBER_OF_COLOMNS; u8Iterator++)
    {
        SRG_u8CONTROL_PORT |= (1<<SRG_bSCK);

        SRG_u8CONTROL_PORT |= (1<<SRG_bSI);

        SRG_u8CONTROL_PORT &= ~(1<<SRG_bSCK);
    }
    
    SRG_u8CONTROL_PORT |= (1<<SRG_bRCK);
    SRG_u8CONTROL_PORT &= ~(1<<SRG_bSI);
    SRG_u8CONTROL_PORT &= ~(1<<SRG_bRCK);


}


void SRG_vidPutData(u8 u8Data, TYP_tu8Bool bFirst)
{
    
    if (bFirst == TYP_u8TRUE)
    {
        SRG_u8CONTROL_PORT &= ~(1<<SRG_bSI);
		
    }
	SRG_u8DATA_PORT &= SRG_u8CLEAR_DATA_PORT;
    /*shift the SI*/
    SRG_u8CONTROL_PORT |= (1<<SRG_bSCK);
    SRG_u8CONTROL_PORT |= (1<<SRG_bRCK);

    /* Put the Data on the port.*/
    u8Data &= ~(SRG_u8CLEAR_DATA_PORT);
    SRG_u8DATA_PORT &= SRG_u8CLEAR_DATA_PORT;
    SRG_u8DATA_PORT |= u8Data;

    SRG_u8CONTROL_PORT &= ~(1<<SRG_bSCK);
    SRG_u8CONTROL_PORT &= ~(1<<SRG_bRCK);

    SRG_u8CONTROL_PORT |= (1<<SRG_bSI);

    
}

/********************************/
/*	Local Functions' Definition */
/********************************/



